libxc: convert gnttab interfaces to use an opaque handle type
authorIan Campbell <ian.campbell@citrix.com>
Thu, 23 Dec 2010 15:32:52 +0000 (15:32 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 23 Dec 2010 15:32:52 +0000 (15:32 +0000)
The xc_interface previously passed to xc_gnttab_* was only used for
logging which can now be done via the xc_gnttab handle instead.

This makes the interface consistent with the changes made to the main
interface in 21483:779c0ef9682c.

Also update QEMU_TAG to pull in the corresponding qemu change.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Config.mk
tools/fs-back/fs-backend.c
tools/fs-back/fs-backend.h
tools/fs-back/fs-ops.c
tools/libxc/xc_linux.c
tools/libxc/xc_minios.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h
tools/libxc/xenctrl.h

index 6cde101f28f93227c46973b0798196785b33939b..3762e7fddcfb6f849f29ab395174f2108297fb52 100644 (file)
--- a/Config.mk
+++ b/Config.mk
@@ -185,9 +185,9 @@ endif
 # CONFIG_QEMU ?= ../qemu-xen.git
 CONFIG_QEMU ?= $(QEMU_REMOTE)
 
-QEMU_TAG ?= b7754ca4a80e9a53b848796c860d19d6fa7a6d08
-# Thu Dec 23 15:21:52 2010 +0000
-# qemu-xen: update for libxc evtchn interface change
+QEMU_TAG ?= ead83f3f9bc4516f845fbbe23204872eed3e8432
+# Thu Dec 23 15:29:37 2010 +0000
+# qemu-xen: update for libxc gnttab interface change
 
 # Optional components
 XENSTAT_XENTOP     ?= y
index e09a4f70af71cee281c08551de59969cb66f2bab..3f4b1640f7f552cc770d1880926b4d314471ea3d 100644 (file)
@@ -168,9 +168,8 @@ void terminate_mount_request(struct fs_mount *mount)
     }
     xenbus_write_backend_state(mount, STATE_CLOSED);
 
-    xc_gnttab_munmap(mount->xch, mount->gnth,
-                     mount->ring.sring, mount->shared_ring_size);
-    xc_gnttab_close(mount->xch, mount->gnth);
+    xc_gnttab_munmap(mount->gnth, mount->ring.sring, mount->shared_ring_size);
+    xc_gnttab_close(mount->gnth);
     xc_evtchn_unbind(mount->evth, mount->local_evtchn);
     xc_evtchn_close(mount->evth);
 
@@ -242,15 +241,15 @@ static void handle_connection(int frontend_dom_id, int export_id, char *frontend
         FS_DEBUG("ERROR: Couldn't bind evtchn!\n");
         goto error;
     }
-    mount->gnth = -1;
-    mount->gnth = xc_gnttab_open(mount->xch);
-    if (mount->gnth < 0) {
+    mount->gnth = NULL;
+    mount->gnth = xc_gnttab_open(NULL, 0);
+    if (mount->gnth == NULL) {
         FS_DEBUG("ERROR: Couldn't open gnttab!\n");
         goto error;
     }
     for(i=0; i<mount->shared_ring_size; i++)
         dom_ids[i] = mount->dom_id;
-    sring = xc_gnttab_map_grant_refs(mount->xch, mount->gnth,
+    sring = xc_gnttab_map_grant_refs(mount->gnth,
                                      mount->shared_ring_size,
                                      dom_ids,
                                      mount->grefs,
@@ -283,10 +282,9 @@ static void handle_connection(int frontend_dom_id, int export_id, char *frontend
 error:
     xenbus_write_backend_state(mount, STATE_CLOSED);
     if (sring)
-        xc_gnttab_munmap(mount->xch, mount->gnth,
-                         mount->ring.sring, mount->shared_ring_size);
-    if (mount->gnth > 0)
-        xc_gnttab_close(mount->xch, mount->gnth);
+        xc_gnttab_munmap(mount->gnth, mount->ring.sring, mount->shared_ring_size);
+    if (mount->gnth != NULL)
+        xc_gnttab_close(mount->gnth);
     if (mount->local_evtchn > 0)
         xc_evtchn_unbind(mount->evth, mount->local_evtchn);
     if (mount->evth != NULL)
index 37f851cc634aa2188fae115f45b0493b6898defc..8815aa02d31f0b1733250ea3d6ba06448cd3bd01 100644 (file)
@@ -47,7 +47,7 @@ struct fs_mount
     xc_interface *xch; /* just for error logging, so a dummy */
     xc_evtchn *evth;               /* Handle to the event channel */
     evtchn_port_t local_evtchn;
-    int gnth;
+    xc_gnttab *gnth;
     int shared_ring_size;             /* in pages */
     struct fsif_back_ring ring;
     int nr_entries;
index 8f8759245112b134f2291399c786aa9cee404f7e..31ac6eda0b42eeede71d51b574f8fa45f0927f34 100644 (file)
@@ -75,7 +75,7 @@ static void dispatch_file_open(struct fs_mount *mount, struct fsif_request *req)
 
     FS_DEBUG("Dispatching file open operation (gref=%d).\n", req->u.fopen.gref);
     /* Read the request, and open file */
-    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->gnth,
                                         mount->dom_id,
                                         req->u.fopen.gref,
                                         PROT_READ);
@@ -99,7 +99,7 @@ static void dispatch_file_open(struct fs_mount *mount, struct fsif_request *req)
         }
     }
 out:
-    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -159,7 +159,7 @@ static void dispatch_file_read(struct fs_mount *mount, struct fsif_request *req)
     assert(req->u.fread.len > 0); 
     count = (req->u.fread.len - 1) / XC_PAGE_SIZE + 1;
     assert(count <= FSIF_NR_READ_GNTS);
-    buf = xc_gnttab_map_domain_grant_refs(mount->xch, mount->gnth,
+    buf = xc_gnttab_map_domain_grant_refs(mount->gnth,
                                           count,
                                           mount->dom_id,
                                           req->u.fread.grefs,
@@ -192,8 +192,7 @@ static void dispatch_file_read(struct fs_mount *mount, struct fsif_request *req)
     priv_req->aiocb.aio_sigevent.sigev_value.sival_ptr = priv_req;
     if (aio_read(&priv_req->aiocb) < 0) {
         FS_DEBUG("ERROR: aio_read failed errno=%d\n", errno);
-        xc_gnttab_munmap(mount->xch, mount->gnth,
-                         priv_req->page, priv_req->count);
+        xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count);
         terminate_mount_request(mount);
     }
 
@@ -209,7 +208,7 @@ static void end_file_read(struct fs_mount *mount, struct fs_request *priv_req)
     uint16_t req_id;
 
     /* Release the grant */
-    if (xc_gnttab_munmap(mount->xch, mount->gnth,
+    if (xc_gnttab_munmap(mount->gnth,
                          priv_req->page, priv_req->count) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
@@ -236,7 +235,7 @@ static void dispatch_file_write(struct fs_mount *mount, struct fsif_request *req
     assert(req->u.fwrite.len > 0); 
     count = (req->u.fwrite.len - 1) / XC_PAGE_SIZE + 1;
     assert(count <= FSIF_NR_WRITE_GNTS);
-    buf = xc_gnttab_map_domain_grant_refs(mount->xch, mount->gnth,
+    buf = xc_gnttab_map_domain_grant_refs(mount->gnth,
                                           count,
                                           mount->dom_id,
                                           req->u.fwrite.grefs,
@@ -269,7 +268,7 @@ static void dispatch_file_write(struct fs_mount *mount, struct fsif_request *req
     priv_req->aiocb.aio_sigevent.sigev_value.sival_ptr = priv_req;
     if (aio_write(&priv_req->aiocb) < 0) {
         FS_DEBUG("ERROR: aio_write failed errno=%d\n", errno);
-        xc_gnttab_munmap(mount->xch, mount->gnth,
+        xc_gnttab_munmap(mount->gnth,
                          priv_req->page, priv_req->count);
         terminate_mount_request(mount);
     }
@@ -287,7 +286,7 @@ static void end_file_write(struct fs_mount *mount, struct fs_request *priv_req)
     uint16_t req_id;
 
     /* Release the grant */
-    if (xc_gnttab_munmap(mount->xch, mount->gnth,
+    if (xc_gnttab_munmap(mount->gnth,
                          priv_req->page, priv_req->count) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
@@ -395,7 +394,7 @@ static void dispatch_remove(struct fs_mount *mount, struct fsif_request *req)
 
     FS_DEBUG("Dispatching remove operation (gref=%d).\n", req->u.fremove.gref);
     /* Read the request, and open file */
-    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->gnth,
                                         mount->dom_id,
                                         req->u.fremove.gref,
                                         PROT_READ);
@@ -409,7 +408,7 @@ static void dispatch_remove(struct fs_mount *mount, struct fsif_request *req)
         ret = remove(file_name);
     }
     FS_DEBUG("Got ret: %d\n", ret);
-    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -437,7 +436,7 @@ static void dispatch_rename(struct fs_mount *mount, struct fsif_request *req)
 
     FS_DEBUG("Dispatching rename operation (gref=%d).\n", req->u.fremove.gref);
     /* Read the request, and open file */
-    buf = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
+    buf = xc_gnttab_map_grant_ref(mount->gnth,
                                   mount->dom_id,
                                   req->u.frename.gref,
                                   PROT_READ);
@@ -455,7 +454,7 @@ static void dispatch_rename(struct fs_mount *mount, struct fsif_request *req)
         ret = rename(old_file_name, new_file_name);
     }
     FS_DEBUG("Got ret: %d\n", ret);
-    if (xc_gnttab_munmap(mount->xch, mount->gnth, buf, 1) != 0) {
+    if (xc_gnttab_munmap(mount->gnth, buf, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -487,7 +486,7 @@ static void dispatch_create(struct fs_mount *mount, struct fsif_request *req)
     /* Read the request, and create file/directory */
     mode = req->u.fcreate.mode;
     directory = req->u.fcreate.directory;
-    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->gnth,
                                         mount->dom_id,
                                         req->u.fcreate.gref,
                                         PROT_READ);
@@ -523,7 +522,7 @@ static void dispatch_create(struct fs_mount *mount, struct fsif_request *req)
         }
     }
 out:
-    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -551,7 +550,7 @@ static void dispatch_list(struct fs_mount *mount, struct fsif_request *req)
     FS_DEBUG("Dispatching list operation (gref=%d).\n", req->u.flist.gref);
     /* Read the request, and list directory */
     offset = req->u.flist.offset;
-    buf = file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
+    buf = file_name = xc_gnttab_map_grant_ref(mount->gnth,
                                         mount->dom_id,
                                         req->u.flist.gref,
                                         PROT_READ | PROT_WRITE);
@@ -599,7 +598,7 @@ error_out:
     ret_val = ((nr_files << NR_FILES_SHIFT) & NR_FILES_MASK) | 
               ((error_code << ERROR_SHIFT) & ERROR_MASK) | 
               (dirent != NULL ? HAS_MORE_FLAG : 0);
-    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -654,7 +653,7 @@ static void dispatch_fs_space(struct fs_mount *mount, struct fsif_request *req)
 
     FS_DEBUG("Dispatching fs space operation (gref=%d).\n", req->u.fspace.gref);
     /* Read the request, and open file */
-    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->gnth,
                                         mount->dom_id,
                                         req->u.fspace.gref,
                                         PROT_READ);
@@ -670,7 +669,7 @@ static void dispatch_fs_space(struct fs_mount *mount, struct fsif_request *req)
     if(ret >= 0)
         ret = stat.f_bsize * stat.f_bfree;
 
-    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
index f2a24c3ab53b35d1d882cb59cbfeb448694be47c..13cb802d5dfd2dd01beeb4a43a75f61dbfd37713 100644 (file)
@@ -443,18 +443,17 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
     errno = saved_errno;
 }
 
-int xc_gnttab_open(xc_interface *xch)
+int xc_gnttab_open_core(xc_gnttab *xcg)
 {
     return open(DEVXEN "gntdev", O_RDWR);
 }
 
-int xc_gnttab_close(xc_interface *xch, int xcg_handle)
+int xc_gnttab_close_core(xc_gnttab *xcg)
 {
-    return close(xcg_handle);
+    return close(xcg->fd);
 }
 
-void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle,
-                              uint32_t domid, uint32_t ref, int prot)
+void *xc_gnttab_map_grant_ref(xc_gnttab *xch, uint32_t domid, uint32_t ref, int prot)
 {
     struct ioctl_gntdev_map_grant_ref map;
     void *addr;
@@ -463,13 +462,13 @@ void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle,
     map.refs[0].domid = domid;
     map.refs[0].ref = ref;
 
-    if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) {
+    if ( ioctl(xch->fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) {
         PERROR("xc_gnttab_map_grant_ref: ioctl MAP_GRANT_REF failed");
         return NULL;
     }
 
 mmap_again:    
-    addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, xcg_handle, map.index);
+    addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, xch->fd, map.index);
     if ( addr == MAP_FAILED )
     {
         int saved_errno = errno;
@@ -484,7 +483,7 @@ mmap_again:
         PERROR("xc_gnttab_map_grant_ref: mmap failed");
         unmap_grant.index = map.index;
         unmap_grant.count = 1;
-        ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
+        ioctl(xch->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
         errno = saved_errno;
         return NULL;
     }
@@ -492,8 +491,7 @@ mmap_again:
     return addr;
 }
 
-static void *do_gnttab_map_grant_refs(xc_interface *xch,
-                                      int xcg_handle, uint32_t count,
+static void *do_gnttab_map_grant_refs(xc_gnttab *xch, uint32_t count,
                                       uint32_t *domids, int domids_stride,
                                       uint32_t *refs, int prot)
 {
@@ -514,12 +512,12 @@ static void *do_gnttab_map_grant_refs(xc_interface *xch,
 
     map->count = count;
 
-    if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) {
+    if ( ioctl(xch->fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) {
         PERROR("xc_gnttab_map_grant_refs: ioctl MAP_GRANT_REF failed");
         goto out;
     }
 
-    addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, xcg_handle,
+    addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, xch->fd,
                 map->index);
     if ( addr == MAP_FAILED )
     {
@@ -530,7 +528,7 @@ static void *do_gnttab_map_grant_refs(xc_interface *xch,
         PERROR("xc_gnttab_map_grant_refs: mmap failed");
         unmap_grant.index = map->index;
         unmap_grant.count = count;
-        ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
+        ioctl(xch->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
         errno = saved_errno;
         addr = NULL;
     }
@@ -541,22 +539,19 @@ static void *do_gnttab_map_grant_refs(xc_interface *xch,
     return addr;
 }
 
-void *xc_gnttab_map_grant_refs(xc_interface *xch,
-                               int xcg_handle, uint32_t count, uint32_t *domids,
+void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t *domids,
                                uint32_t *refs, int prot)
 {
-    return do_gnttab_map_grant_refs(xch, xcg_handle, count, domids, 1, refs, prot);
+    return do_gnttab_map_grant_refs(xcg, count, domids, 1, refs, prot);
 }
 
-void *xc_gnttab_map_domain_grant_refs(xc_interface *xch,
-                                      int xcg_handle, uint32_t count,
+void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, uint32_t count,
                                       uint32_t domid, uint32_t *refs, int prot)
 {
-    return do_gnttab_map_grant_refs(xch, xcg_handle, count, &domid, 0, refs, prot);
+    return do_gnttab_map_grant_refs(xcg, count, &domid, 0, refs, prot);
 }
 
-int xc_gnttab_munmap(xc_interface *xch,
-                     int xcg_handle, void *start_address, uint32_t count)
+int xc_gnttab_munmap(xc_gnttab *xcg, void *start_address, uint32_t count)
 {
     struct ioctl_gntdev_get_offset_for_vaddr get_offset;
     struct ioctl_gntdev_unmap_grant_ref unmap_grant;
@@ -572,7 +567,7 @@ int xc_gnttab_munmap(xc_interface *xch,
      * mmap() the pages.
      */
     get_offset.vaddr = (unsigned long)start_address;
-    if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR,
+    if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR,
                      &get_offset)) )
         return rc;
 
@@ -589,20 +584,19 @@ int xc_gnttab_munmap(xc_interface *xch,
     /* Finally, unmap the driver slots used to store the grant information. */
     unmap_grant.index = get_offset.offset;
     unmap_grant.count = count;
-    if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) )
+    if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) )
         return rc;
 
     return 0;
 }
 
-int xc_gnttab_set_max_grants(xc_interface *xch,
-                             int xcg_handle, uint32_t count)
+int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count)
 {
     struct ioctl_gntdev_set_max_grants set_max;
     int rc;
 
     set_max.count = count;
-    if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) )
+    if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) )
         return rc;
 
     return 0;
index c8b0007ce6ad24b47be6083b8641b2cd2f433e9b..d5f93f59eeb9297da529d0ba667b71c7fb428585 100644 (file)
@@ -375,17 +375,17 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
         fsync(fd);
 }
 
-int xc_gnttab_open(xc_interface *xch)
+int xc_gnttab_open_core(xc_gnttab *xcg)
 {
-    int xcg_handle;
-    xcg_handle = alloc_fd(FTYPE_GNTMAP);
-    gntmap_init(&files[xcg_handle].gntmap);
-    return xcg_handle;
+    int fd;
+    fd = alloc_fd(FTYPE_GNTMAP);
+    gntmap_init(&files[fd].gntmap);
+    return fd;
 }
 
-int xc_gnttab_close(xc_interface *xch, int xcg_handle)
+int xc_gnttab_close_core(xc_gnttab *xcg)
 {
-    return close(xcg_handle);
+    return close(xcg->fd);
 }
 
 void minios_gnttab_close_fd(int fd)
@@ -394,50 +394,50 @@ void minios_gnttab_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
-void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle,
+void *xc_gnttab_map_grant_ref(xc_gnttab *xcg,
                               uint32_t domid,
                               uint32_t ref,
                               int prot)
 {
-    return gntmap_map_grant_refs(&files[xcg_handle].gntmap,
+    return gntmap_map_grant_refs(&files[xcg->fd].gntmap,
                                  1,
                                  &domid, 0,
                                  &ref,
                                  prot & PROT_WRITE);
 }
 
-void *xc_gnttab_map_grant_refs(xc_interface *xch, int xcg_handle,
+void *xc_gnttab_map_grant_refs(xc_gnttab *xcg,
                                uint32_t count,
                                uint32_t *domids,
                                uint32_t *refs,
                                int prot)
 {
-    return gntmap_map_grant_refs(&files[xcg_handle].gntmap,
+    return gntmap_map_grant_refs(&files[xcg->fd].gntmap,
                                  count,
                                  domids, 1,
                                  refs,
                                  prot & PROT_WRITE);
 }
 
-void *xc_gnttab_map_domain_grant_refs(xc_interface *xch, int xcg_handle,
+void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg,
                                       uint32_t count,
                                       uint32_t domid,
                                       uint32_t *refs,
                                       int prot)
 {
-    return gntmap_map_grant_refs(&files[xcg_handle].gntmap,
+    return gntmap_map_grant_refs(&files[xcg->fd].gntmap,
                                  count,
                                  &domid, 0,
                                  refs,
                                  prot & PROT_WRITE);
 }
 
-int xc_gnttab_munmap(xc_interface *xch, int xcg_handle,
+int xc_gnttab_munmap(xc_gnttab *xcg,
                      void *start_address,
                      uint32_t count)
 {
     int ret;
-    ret = gntmap_munmap(&files[xcg_handle].gntmap,
+    ret = gntmap_munmap(&files[xcg->fd].gntmap,
                         (unsigned long) start_address,
                         count);
     if (ret < 0) {
@@ -447,11 +447,11 @@ int xc_gnttab_munmap(xc_interface *xch, int xcg_handle,
     return ret;
 }
 
-int xc_gnttab_set_max_grants(xc_interface *xch, int xcg_handle,
+int xc_gnttab_set_max_grants(xc_gnttab *xcg,
                              uint32_t count)
 {
     int ret;
-    ret = gntmap_set_max_grants(&files[xcg_handle].gntmap,
+    ret = gntmap_set_max_grants(&files[xcg->fd].gntmap,
                                 count);
     if (ret < 0) {
         errno = -ret;
index 4cd89209fa8086ac7e616c784fa110c0edebe872..3ee500bbd19e2aff52569f1975dee8f54a37214c 100644 (file)
@@ -115,6 +115,18 @@ int xc_evtchn_close(xc_evtchn *xce)
     return xc_interface_close_common(xce, &xc_evtchn_close_core);
 }
 
+xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
+                             unsigned open_flags)
+{
+    return xc_interface_open_common(logger, NULL, open_flags,
+                                    XC_INTERFACE_GNTTAB, &xc_gnttab_open_core);
+}
+
+int xc_gnttab_close(xc_gnttab *xcg)
+{
+    return xc_interface_close_common(xcg, &xc_gnttab_close_core);
+}
+
 static pthread_key_t errbuf_pkey;
 static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
 
index 5cd936cb72ea564848327a007b01829b90b17c15..8f3b2a2d0d93ddd2746accafe35383a340feb4c4 100644 (file)
@@ -68,6 +68,7 @@
 enum xc_interface_type {
        XC_INTERFACE_PRIVCMD,
        XC_INTERFACE_EVTCHN,
+       XC_INTERFACE_GNTTAB,
 };
 
 struct xc_interface_core {
@@ -269,6 +270,9 @@ int xc_interface_close_core(struct xc_interface_core *xch); /* no logging */
 int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */
 int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */
 
+int xc_gnttab_open_core(struct xc_interface_core *xcg); /* returns fd, logs errors */
+int xc_gnttab_close_core(struct xc_interface_core *xcg); /* no logging */
+
 void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
                             size_t size, int prot, size_t chunksize,
                             privcmd_mmap_entry_t entries[], int nentries);
index abfeedb582563b8d2d61396612282d4cbfe4f1ac..18d778bdb1f995f4da156a56be404c9cfa0e0da5 100644 (file)
 
 typedef struct xc_interface_core xc_interface;
 typedef struct xc_interface_core xc_evtchn;
+typedef struct xc_interface_core xc_gnttab;
 typedef enum xc_error_code xc_error_code;
 
 
@@ -1239,25 +1240,25 @@ int xc_domain_subscribe_for_suspend(
 /*
  * Return an fd onto the grant table driver.  Logs errors.
  */
-int xc_gnttab_open(xc_interface *xch);
+xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
+                         unsigned open_flags);
 
 /*
  * Close a handle previously allocated with xc_gnttab_open().
  * Never logs errors.
  */
-int xc_gnttab_close(xc_interface *xch, int xcg_handle);
+int xc_gnttab_close(xc_gnttab *xcg);
 
 /*
  * Memory maps a grant reference from one domain to a local address range.
  * Mappings should be unmapped with xc_gnttab_munmap.  Logs errors.
  *
- * @parm xcg_handle a handle on an open grant table interface
+ * @parm xcg a handle on an open grant table interface
  * @parm domid the domain to map memory from
  * @parm ref the grant reference ID to map
  * @parm prot same flag as in mmap()
  */
-void *xc_gnttab_map_grant_ref(xc_interface *xch,
-                              int xcg_handle,
+void *xc_gnttab_map_grant_ref(xc_gnttab *xcg,
                               uint32_t domid,
                               uint32_t ref,
                               int prot);
@@ -1267,15 +1268,14 @@ void *xc_gnttab_map_grant_ref(xc_interface *xch,
  * contiguous local address range. Mappings should be unmapped with
  * xc_gnttab_munmap.  Logs errors.
  *
- * @parm xcg_handle a handle on an open grant table interface
+ * @parm xcg a handle on an open grant table interface
  * @parm count the number of grant references to be mapped
  * @parm domids an array of @count domain IDs by which the corresponding @refs
  *              were granted
  * @parm refs an array of @count grant references to be mapped
  * @parm prot same flag as in mmap()
  */
-void *xc_gnttab_map_grant_refs(xc_interface *xch,
-                               int xcg_handle,
+void *xc_gnttab_map_grant_refs(xc_gnttab *xcg,
                                uint32_t count,
                                uint32_t *domids,
                                uint32_t *refs,
@@ -1286,14 +1286,13 @@ void *xc_gnttab_map_grant_refs(xc_interface *xch,
  * contiguous local address range. Mappings should be unmapped with
  * xc_gnttab_munmap.  Logs errors.
  *
- * @parm xcg_handle a handle on an open grant table interface
+ * @parm xcg a handle on an open grant table interface
  * @parm count the number of grant references to be mapped
  * @parm domid the domain to map memory from
  * @parm refs an array of @count grant references to be mapped
  * @parm prot same flag as in mmap()
  */
-void *xc_gnttab_map_domain_grant_refs(xc_interface *xch,
-                                      int xcg_handle,
+void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg,
                                       uint32_t count,
                                       uint32_t domid,
                                       uint32_t *refs,
@@ -1303,8 +1302,7 @@ void *xc_gnttab_map_domain_grant_refs(xc_interface *xch,
  * Unmaps the @count pages starting at @start_address, which were mapped by a
  * call to xc_gnttab_map_grant_ref or xc_gnttab_map_grant_refs. Never logs.
  */
-int xc_gnttab_munmap(xc_interface *xch,
-                     int xcg_handle,
+int xc_gnttab_munmap(xc_gnttab *xcg,
                      void *start_address,
                      uint32_t count);
 
@@ -1319,8 +1317,7 @@ int xc_gnttab_munmap(xc_interface *xch,
  *      and it may not be possible to satisfy requests up to the maximum number
  *      of grants.
  */
-int xc_gnttab_set_max_grants(xc_interface *xch,
-                             int xcg_handle,
+int xc_gnttab_set_max_grants(xc_gnttab *xcg,
                             uint32_t count);
 
 int xc_gnttab_op(xc_interface *xch, int cmd,